package grpc

import (
	"fmt"

	"github.com/go-playground/validator/v10"
	"gitverse.ru/dlc/similarity-compiler/internal/initialize"
	"gitverse.ru/dlc/similarity-compiler/internal/interface/controllers/grpc/compiler"
	"gitverse.ru/dlc/similarity-compiler/pkg/errors"
)

type ControllersDeps struct {
	Services *initialize.Services `validate:"required"`
}

type Controllers struct {
	Compiler *compiler.Controller
}

func NewControllers(deps ControllersDeps) (*Controllers, errors.Error) {
	if err := validator.New().Struct(deps); err != nil {
		return nil, errors.NewWithError(fmt.Errorf("validate deps: %w", err), errors.ErrInternalError)
	}

	compilerController, err := compiler.New(compiler.Deps{
		CompilerService: deps.Services.CompilerService,
	})
	if err != nil {
		return nil, err.Wrap("initialize compiler controller")
	}

	return &Controllers{
		Compiler: compilerController,
	}, nil
}
